#include "CComputer.h"
#include <msclr/gcroot.h>
#include "CHardware.h"

#using "OpenHardwareMonitorLib.dll"

using namespace msclr;
using namespace System::Runtime::InteropServices;

namespace NOpenHardwareMonitor {

namespace NHardware {

class CComputerPrivate
{
public:
	gcroot<OpenHardwareMonitor::Hardware::Computer^> mComputer;
};


CComputer::CComputer()
	: d_ptr(new CComputerPrivate())
{
	Q_D(CComputer);

	d->mComputer = gcnew OpenHardwareMonitor::Hardware::Computer();
}

CComputer::~CComputer()
{  }

void CComputer::Open()
{ Q_D(CComputer); d->mComputer->Open(); }

void CComputer::Close()
{ Q_D(CComputer); d->mComputer->Close(); }

void CComputer::Release()
{ delete this; }

QString CComputer::GetReport() const
{
	Q_D(const CComputer);

	char* m_ReportChar = (char*)(void*)Marshal::StringToHGlobalAnsi(d->mComputer->GetReport());
	return QString(m_ReportChar);
}

bool CComputer::IsCPUEnabled() const
{ Q_D(const CComputer); return d->mComputer->CPUEnabled; }

void CComputer::CPUEnable(bool Enable)
{ Q_D(CComputer); d->mComputer->CPUEnabled = Enable; }

bool CComputer::IsGPUEnabled() const
{ Q_D(const CComputer); return d->mComputer->GPUEnabled; }

void CComputer::GPUEnable(bool Enable)
{ Q_D(CComputer); d->mComputer->GPUEnabled = Enable; }

bool CComputer::IsHDDEnabled() const
{ Q_D(const CComputer); return d->mComputer->HDDEnabled; }

void CComputer::HDDEnable(bool Enable)
{ Q_D(CComputer); d->mComputer->HDDEnabled = Enable; }

bool CComputer::IsMainboardEnabled() const
{ Q_D(const CComputer); return d->mComputer->MainboardEnabled; }

void CComputer::MainboardEnable(bool Enable)
{ Q_D(CComputer); d->mComputer->MainboardEnabled = Enable; }

bool CComputer::IsRAMEnabled() const
{ Q_D(const CComputer); return d->mComputer->RAMEnabled; }

void CComputer::RAMEnable(bool Enable)
{ Q_D(CComputer); d->mComputer->RAMEnabled = Enable; }

bool CComputer::IsFanControllerEnabled() const
{ Q_D(const CComputer); return d->mComputer->FanControllerEnabled; }

void CComputer::FanControllerEnable(bool Enable)
{ Q_D(CComputer); d->mComputer->FanControllerEnabled = Enable; }

qint32 CComputer::GetHardwareCount() const
{ Q_D(const CComputer); return d->mComputer->Hardware->Length; }

IHardware* CComputer::GetHardware(const qint32& Index)
{ Q_D(CComputer); return new CHardware(this, Index); }

void* CComputer::GetHandle() const
{ Q_D(const CComputer); return (void*)&d->mComputer; }


}}

